package vip.websky.project.web.config;


import com.alibaba.druid.util.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import vip.websky.project.core.utils.SpringContextUtil;
import vip.websky.project.module.dto.RequestDTO;
import vip.websky.project.module.dto.ResponseDTO;
import vip.websky.project.user.service.UserRoleService;
import vip.websky.project.user.service.UserService;

import java.util.function.Function;

/**
 * 接口定义
 *
 * @createAt: 2017/8/10 12:39
 */
@Slf4j
@Getter
@AllArgsConstructor
public enum InterfaceEnum {

    USER_USER_001("user_user_001", SpringContextUtil.getBean(UserService.class)::addUser,false,"添加用户信息"),
    USER_USER_002("user_user_002", SpringContextUtil.getBean(UserService.class)::getUser,false,"获取用户信息"),
    USER_USER_003("user_user_003", SpringContextUtil.getBean(UserService.class)::getUserList,false,"获取用户列表"),
    USER_USER_004("user_user_004", SpringContextUtil.getBean(UserService.class)::editUser,false,"修改用户信息"),
    USER_USER_005("user_user_005", SpringContextUtil.getBean(UserService.class)::removeUser,false,"删除用户信息"),

    USER_USER_006("user_userRole_001", SpringContextUtil.getBean(UserRoleService.class)::addUserRoleBatch,false,"删除用户信息"),
    USER_USER_007("user_userRole_002", SpringContextUtil.getBean(UserRoleService.class)::editUserRoleBatch,false,"删除用户信息"),
    USER_USER_008("user_userRole_003", SpringContextUtil.getBean(UserRoleService.class)::removeUserRoleBatch,false,"删除用户信息"),
    ;

    /**
     * 接口 code
     * 模块 + 子模块 + 顺序号
     */
    private String code;

    /**
     * 业务方法
     */
    private Function<RequestDTO,ResponseDTO> function;

    private boolean verifyToken;//是否校验 token;

    /**
     * 接口描述
     */
    private String desc;

    public static InterfaceEnum getInterfaceEnumByCode(String code){
        for (InterfaceEnum interfaceEnum: InterfaceEnum.values()){
            if (StringUtils.equals(code,interfaceEnum.getCode())){
                return interfaceEnum;
            }
        }
        return null;
    }
}
